/*
@title: The Two Bananas Game
@description: "The Two Bananas Game" is a playful multiplayer experience centered around two bananas seeking revenge through competitive minigames. Players engage in various challenges like racing, avoiding lava, playing soccer, scoring in basketball, and sumo wrestling.
@author: sridhar
@tags: []
@addedOn: 2024-07-29
*/

// all sprites
const player1 = "p"
const player2 = "t"
const soccerBall = "s"
const leftGoal = "l"
const rightGoal = "r"
const sumoBounds = "b"
const bBallBasketLeft = "a"
const bBallBasketRight = "c"
const bBall = "d"
const finishLine = "f"
const obstacle = "o"
const obstacle2 = "q"
const lava = "e"

// music
let tracks = [
tune`
0,
166.66649999999998: B3^166.66649999999998,
166.66649999999998: A3^166.66649999999998,
166.66649999999998: G3^166.66649999999998,
166.66649999999998: A3^166.66649999999998,
166.66650000000004: G3^166.66650000000004,
333.33299999999986: F3^166.66649999999993,
166.66650000000004: D3^166.66650000000004,
166.66650000000004: D3^166.66650000000004,
166.66650000000004: E3^166.66650000000004,
166.66649999999981: G4^166.66649999999981,
166.66650000000004: F4^166.66650000000004,
166.66650000000004: G4^166.66650000000004,
166.66649999999981: F4^166.66649999999981,
166.66650000000027: A4^166.66650000000027,
166.66649999999981: A4^166.66649999999981,
166.66649999999981: F3^166.66649999999981,
166.66650000000027: G3^166.66650000000027,
166.66649999999981: G3^166.66649999999981,
166.66650000000027: B3^166.66650000000027,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66650000000027: F3^166.66650000000027,
166.66649999999981: F3^166.66649999999981,
166.66650000000027: F4^166.66650000000027,
166.66649999999981: E4^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: E4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66650000000072: G4^166.66650000000072,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: B3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66650000000072: G3^166.66650000000072,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
333.33299999999963: F3^166.66649999999981,
166.66650000000072: D3^166.66650000000072,
166.66649999999981: D3^166.66649999999981,
166.66649999999981: E3^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66650000000072: F4^166.66650000000072,
166.66649999999981: A4^166.66649999999981,
166.66649999999981: A4^166.66649999999981,
166.66650000000072: F3^166.66650000000072,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: B3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: F3^166.66649999999981,
166.66649999999981: F3^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: E4^166.66649999999981,
166.6665000000016: F4^166.6665000000016,
166.66649999999981: E4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: B3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
333.33300000000145: F3^166.6665000000016,
166.66649999999981: D3^166.66649999999981,
166.66649999999981: D3^166.66649999999981,
166.66649999999981: E3^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: A4^166.66649999999981,
166.6665000000016: A4^166.6665000000016,
166.66649999999981: F3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: B3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: F3^166.66649999999981,
166.66649999999981: F3^166.66649999999981,
166.66649999999981: F4^166.66649999999981,
166.66649999999981: E4^166.66649999999981,
166.6665000000016: F4^166.6665000000016,
166.66649999999981: E4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: G4^166.66649999999981,
166.66649999999981: G3^166.66649999999981,
166.66649999999981: A3^166.66649999999981,
166.66649999999981: B3^166.66649999999981,
166.6665000000016: A3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
333.33299999999963: F3^166.6665000000016,
166.6665000000016: D3^166.6665000000016,
166.66649999999805: D3^166.66649999999805,
166.6665000000016: E3^166.6665000000016,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: A4^166.6665000000016,
166.66649999999805: A4^166.66649999999805,
166.6665000000016: F3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: B3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: F3^166.66649999999805,
166.6665000000016: F3^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: E4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: E4^166.6665000000016,
166.66649999999805: G4^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.6665000000016: B3^166.6665000000016,
166.66649999999805: A3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: A3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
333.33299999999963: F3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.6665000000016: D3^166.6665000000016,
166.66649999999805: E3^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.6665000000016: F4^166.6665000000016,
166.66649999999805: G4^166.66649999999805,
166.6665000000016: F4^166.6665000000016,
166.66649999999805: A4^166.66649999999805,
166.6665000000016: A4^166.6665000000016,
166.66649999999805: F3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: B3^166.6665000000016,
166.66649999999805: A3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.6665000000016: F3^166.6665000000016,
166.66649999999805: F3^166.66649999999805,
166.6665000000016: F4^166.6665000000016,
166.66649999999805: E4^166.66649999999805,
166.6665000000016: F4^166.6665000000016,
166.66649999999805: E4^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: G4^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.6665000000016: A3^166.6665000000016,
166.66649999999805: B3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
333.33299999999963: F3^166.6665000000016,
166.6665000000016: D3^166.6665000000016,
166.66649999999805: D3^166.66649999999805,
166.6665000000016: E3^166.6665000000016,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: A4^166.6665000000016,
166.66649999999805: A4^166.66649999999805,
166.6665000000016: F3^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: B3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.6665000000016: G3^166.6665000000016,
166.66649999999805: F3^166.66649999999805,
166.6665000000016: F3^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: E4^166.6665000000016,
166.66649999999805: F4^166.66649999999805,
166.6665000000016: E4^166.6665000000016,
166.66649999999805: G4^166.66649999999805,
166.6665000000016: G4^166.6665000000016,
166.66649999999805: G3^166.66649999999805,
166.6665000000016: A3^166.6665000000016,
166.6665000000016: B3^166.6665000000016,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
333.3329999999961: F3^166.66649999999805,
166.66650000000516: D3^166.66650000000516,
166.66649999999805: D3^166.66649999999805,
166.66649999999805: E3^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: A4^166.66650000000516,
166.66649999999805: A4^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: B3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: E4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: B3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.66650000000516: D3^166.66650000000516,
166.66649999999805: E3^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: A4^166.66649999999805,
166.66650000000516: A4^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: B3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: F3^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: B3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
333.3330000000032: F3^166.66650000000516,
166.66649999999805: D3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.66650000000516: E3^166.66650000000516,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: A4^166.66649999999805,
166.66649999999805: A4^166.66649999999805,
166.66650000000516: F3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: B3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66650000000516: F3^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: E4^166.66650000000516,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: B3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
333.3330000000032: F3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.66649999999805: E3^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: A4^166.66649999999805,
166.66649999999805: A4^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: B3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: B3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
333.3329999999961: F3^166.66649999999805,
166.66650000000516: D3^166.66650000000516,
166.66649999999805: D3^166.66649999999805,
166.66649999999805: E3^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: A4^166.66650000000516,
166.66649999999805: A4^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: B3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66650000000516: E4^166.66650000000516,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: G4^166.66650000000516,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: B3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: A3^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999805,
166.66649999999805: D3^166.66649999999805,
166.66650000000516: D3^166.66650000000516,
166.66649999999805: E3^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: A4^166.66649999999805,
166.66650000000516: A4^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: B3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: G3^166.66649999999805,
166.66650000000516: F3^166.66650000000516,
166.66649999999805: F3^166.66649999999805,
166.66649999999805: F4^166.66649999999805,
166.66649999999805: E4^166.66649999999805,
166.66650000000516: F4^166.66650000000516,
166.66649999999805: E4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66649999999805: G4^166.66649999999805,
166.66650000000516: G3^166.66650000000516,
166.66649999999805: A3^166.66649999999805,
166.66649999999805: B3^166.66649999999805,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: E3^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: E3^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
333.3330000000103: F3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: E3^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: E3^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
333.3329999999961: F3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: E3^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999095,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: E3^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: E3^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
333.3330000000103: F3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: E3^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: E3^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: E3^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
333.3330000000103: F3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66650000000516: E3^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: B3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F3^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: E4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G4^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: A3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
333.3329999999961: F3^166.66649999999095,
166.66650000000516: D3^166.66650000000516,
166.66649999999095: D3^166.66649999999095,
166.66650000000516: E3^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: F4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: A4^166.66649999999095,
166.66650000000516: A4^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: G3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: B3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: G3^166.66650000000516,
166.66649999999095: F3^166.66649999999095,
166.66650000000516: F3^166.66650000000516,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: F4^166.66650000000516,
166.66649999999095: E4^166.66649999999095,
166.66650000000516: G4^166.66650000000516,
166.66650000000516: G4^166.66650000000516,
166.66649999999095: G3^166.66649999999095,
166.66650000000516: A3^166.66650000000516,
166.66650000000516: B3^166.66650000000516,
166.66649999999095: A3^166.66649999999095,
166.66649999999095: G3^166.66649999999095,
166.66650000001937: A3^166.66650000001937,
166.66649999999095: G3^166.66649999999095,
333.3330000000103: F3^166.66649999999095,
166.66649999999095: D3^166.66649999999095,
166.66649999999095: D3^166.66649999999095,
166.66650000001937: E3^166.66650000001937,
166.66649999999095: G4^166.66649999999095,
166.66649999999095: F4^166.66649999999095,
166.66650000001937: G4^166.66650000001937,
166.66649999999095: F4^166.66649999999095,
166.66649999999095: A4^166.66649999999095,
166.66650000001937: A4^166.66650000001937,
166.66649999999095: F3^166.66649999999095,
166.66649999999095: G3^166.66649999999095,
166.66650000001937: G3^166.66650000001937,
166.66649999999095: B3^166.66649999999095,
166.66649999999095: A3^166.66649999999095,
166.66650000001937: G3^166.66650000001937,
166.66649999999095: F3^166.66649999999095,
166.66649999999095: F3^166.66649999999095,
166.66649999999095: F4^166.66649999999095,
166.66650000001937: E4^166.66650000001937,
166.66649999999095: F4^166.66649999999095,
166.66649999999095: E4^166.66649999999095,
166.66650000001937: G4^166.66650000001937,
166.66649999999095: G4^166.66649999999095,
166.66649999999095: G3^166.66649999999095,
133166.5335: A3^166.66650000001937,
`,
tune`
0,
166.66649999999998: B1^166.66649999999998,
166.66649999999998: B1^166.66649999999998,
166.66649999999998: D#2^166.66649999999998,
166.66649999999998: D#2^166.66649999999998,
166.66650000000004: B1^166.66650000000004,
166.66649999999993: B1^166.66649999999993,
166.66649999999993: D#2^166.66649999999993,
166.66650000000004: D#2^166.66650000000004,
166.66650000000004: B1^166.66650000000004,
166.66650000000004: B1^166.66650000000004,
166.66649999999981: D#2^166.66649999999981,
166.66650000000004: D#2^166.66650000000004,
166.66650000000004: B1^166.66650000000004,
166.66649999999981: B1^166.66649999999981,
166.66650000000027: D#2^166.66650000000027,
166.66649999999981: D#2^166.66649999999981,
166.66649999999981: B1^166.66649999999981,
166.66650000000027: B1^166.66650000000027,
166.66649999999981: D#2^166.66649999999981,
166.66650000000027: D#2^166.66650000000027,
166.66649999999981: B1^166.66649999999981,
166.66649999999981: B1^166.66649999999981,
166.66650000000027: D#2^166.66650000000027,
166.66649999999981: D#2^166.66649999999981,
166.66650000000027: B1^166.66650000000027,
166.66649999999981: B1^166.66649999999981,
166.66649999999981: D#2^166.66649999999981,
166.66649999999981: D#2^166.66649999999981,
166.66649999999981: B1^166.66649999999981,
166.66650000000072: B1^166.66650000000072,
166.66649999999981: D#2^166.66649999999981,
5166.6615: D#2^166.66649999999981,
`,
];

// for computer people; one and two stands for player one and player two
let upKeyOne = "w"
let leftKeyOne = "a"
let downKeyOne = "s"
let rightKeyOne = "d"

let upKeyTwo = "i"
let leftKeyTwo = "j"
let downKeyTwo = "k"
let rightKeyTwo = "l"

//bool val where it checks if its the end
let theEnd = false;
// basketball game - to check if ball is at top
let isAtTop = false;
// temp var for bball game
let count = 0;
// to freeze char if its transitioning from one lvl to another
let transitioning = false;

// menu stuffs
let menuPCColor = 9;
let menuConsoleColor = 0;
let menuHelpColor = 0;
let menuSelection = "Play on PC"
let inMenu = true; // DEV TESTING SET TO TRUE WHEN DONE
let inGame = false; // DEV TESTING SET TO FALSE WHEN DONE

// help menu stuffs
let backButtonColor = 9;

// scoring system
let player1Score = 0;
let player2Score = 0;

//randomization
let usedLevels = [];
let allLevelsUsed = false;


// all sprite images are contained in 128x 128 pixels
setLegend(
  [ player1, bitmap`
................
................
.......000......
.......050......
......0550......
......05550.0...
....0005550.0...
....0.0555000...
....0.05550.....
......05550.....
.....055550.....
.....05550......
......000.......
......0.0.......
.....00.00......
................` ], // main characters
  [ player2, bitmap`
................
................
......000.......
......030.......
......0330......
...0.03330......
...0.0333000....
...0003330.0....
.....03330.0....
.....03330......
.....033330.....
......03330.....
.......000......
.......0.0......
......00.00.....
................` ], // main characters
  [ soccerBall, bitmap`
.....00000000...
..000.......00..
.00..........00.
00.00.........0.
0..0......00..00
0.........00...0
0..............0
0..............0
0..00...00.....0
0..00...00.....0
0..............0
00.........0..00
.00.......00..0.
..00........000.
...000.....00...
......000000....`], // soccer game
  [ leftGoal, bitmap`
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..`], // soccer game
  [ rightGoal, bitmap`
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..
.0............0.
..0..........0..`], // soccer game
  [ sumoBounds, bitmap`
0.0.0.0..0.0.0.0
.0.0.0....0.0.0.
0.0.0.0..0.0.0.0
.0.0.0....0.0.0.
0.0.0.0..0.0.0.0
................
0.....0..0.....0
.0.0.0....0.0.0.
0.....0..0.....0
................
................
0.0.0.0..0.0.0.0
.0.0.0....0.0.0.
0.0.0.0..0.0.0.0
.0.0.0....0.0.0.
0.0.0.0..0.0.0.0`], // sumo game
  [ bBallBasketLeft, bitmap`
................
................
................
................
0000000000000000
..0.0.0..0.0.0..
..000000000000..
..0.0.0..0.0.0..
...0000000000...
....0.0..0.0....
....00000000....
....0.0..0.0....
.....00..00.....
......0000......
................
................`], // basketball game
  [ bBallBasketRight, bitmap`
................
................
................
................
0000000000000000
..0.0.0..0.0.0..
..000000000000..
..0.0.0..0.0.0..
...0000000000...
....0.0..0.0....
....00000000....
....0.0..0.0....
.....00..00.....
......0000......
................
................`], // basketball game
  [ bBall, bitmap`
...0000000000...
..099999099990..
.00999990990990.
0990999900990990
0999099990099990
0999909999009990
0999990999900990
0000999099990000
0990099909999990
0999009990999990
0999900999099990
0990990099909990
0999099099990990
.09999909999900.
..099990999990..
...0000000000...`], // basketball game
  [ finishLine, bitmap`
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.
0.0.0.0..0.0.0.0
.0.0.0.00.0.0.0.`], // the race
  [ obstacle, bitmap`
................
.....0000000....
.....0111110....
.....0111110....
.....0111110....
.....0111110....
0000000000000000
0DDDDDDDDDDDDDD0
0D0DDDDDDDDDDDD0
0D0DDDDDDDDDDDD0
0DDDDDDDDDDDDDD0
0000000000000000
..0L0.....0L0...
..000.....000...
................
................`], // the race
  [ obstacle2, bitmap`
......0000......
......0990......
.....009900.....
.....029920.....
.....092290.....
....00999900....
....09999990....
....02999920....
....09222290....
.00009999990000.
0099009999009900
0999900000099990
0099999999999900
.00099999999000.
...000099000....
......0000......`], // the race
  [ lava, bitmap`
0939339303339030
9930339939303339
3393930333393933
9333333993330039
3303903330993333
9339333993339939
3339900330933303
0393333933303933
9330093303933030
3339303333339333
9903333903303393
3333933339393303
3039330333339333
3333333903930393
9393033333393933
0939333930333390`] // hot lava game
)


// sets collision true to these sprites
setSolids(
  [player1, player2, soccerBall, bBall, obstacle, obstacle2]
)

//plays the musics
const playback = tracks.forEach((e) => playTune(e, Infinity));


// game level score
let level = 0 // DEV TESTING SET TO 0 WHEN DONE
// level nums corresponds to map layout
const levels = [
  map`
.....
..p.t
.....
.....`, // menu ; 0
  map`
l...........r
l...........r
l...........r
l...p.s.t...r
l...........r
l...........r
l...........r`, // soccer game;1
  map`
bbbbbbbbb
b.......b
b.......b
b.......b
b.p...t.b
b.......b
b.......b
b.......b
bbbbbbbbb`, // sumo;2
  map`
...............
...............
...............
..a..p.d.t..c..
...............
...............
...............`, // basketball;3
  map`
qqqq.q.q..q..q..q..q..f
p....q.q...o.q..o..q..f
qq...q.q.o...q...q.q.qf
.q.........q..q...o..qf
.qq..o.....q....q..o.qf
.qq..q..q..q..o.q....qf
.q......q..q....o.qqqqf
qq....q.o...o.o.q.q...f
t.....q.o.....q.qqq.o.f
qqqq..q.q..q.q......o.f`, // the race; 4
  map`
................
................
................
................
......p..t......
................
................
................
................`, // hot lava; 5
  map`
........
........
........
........
........
......pt`, // help menu; 6
]

// core functionality
// sets initial map
setMap(levels[level])
// allows sprites to push each other
setPushables({
  [ player1 ]: [ player2, soccerBall, bBall],
  [ player2 ]: [ player1, soccerBall, bBall ],
  [ soccerBall ]: [ player1, player2 ],
  [ bBall ]: [ player1, player2 ]
})

// sets title of the game
function resetGameTitle() {
  if (level == 1) {addText("Soccer Game", {y:1, color: color`2`})}
  else if (level == 2) {addText("Sumo Game", {y:2, color: color`0`})}
  else if (level == 3) {addText("Basketball Game", {y:1, color: color`2`})}
  else if (level == 4) {addText("The Race", {y:1,color:color`2`})}
  else if (level == 5) {addText("Hot Lava", {y:1, color: color`2`})}
}
// initial
resetGameTitle();

// func adds text for main menu
function setMenu() {
  addText("Play on PC", {
    x:1,
    y:1,
    color: color`${menuPCColor}`,
  })
  addText("Play on Console", {
    x:1,
    y:3,
    color: color`${menuConsoleColor}`
  })
  addText("Help", {
    x:1,
    y:5,
    color: color`${menuHelpColor}`
  })
  addText("Left Controls/WASD:", {
    x:1,
    y:10,
    color: color`0`
  })
  addText("to navigate menu", {
    x:1,
    y:11,
    color: color`0`
  })
  addText("Right Down Key/K:", {
    x:1,
    y:13,
    color: color`0`
  })
  addText("to select", {
    x:1,
    y:14,
    color: color`0`
  })
}


// THIS IS ONLY FOR MENU
// menu navigation logic 
if (level == 0) {
  isMenu = true;
  onInput(upKeyOne, () => {
    if (menuPCColor != 9 && inMenu) {
      if (menuHelpColor == 9) {
        menuHelpColor = 0
        menuConsoleColor = 9;
        menuSelection = "Play on Console"
        setMenu()
      }
      else if (menuConsoleColor == 9 ) {
        menuConsoleColor = 0;
        menuPCColor = 9;
        menuSelection = "Play on PC"
        setMenu()
      }
    }
  })
  onInput(downKeyOne, () => {
    if (menuHelpColor != 9 && inMenu) {
      if (menuPCColor == 9) {
        menuPCColor = 0
        menuConsoleColor = 9
        menuSelection = "Play on Console"
        setMenu()
      }
      else if (menuConsoleColor == 9) {
        menuConsoleColor = 0;
        menuHelpColor = 9;
        menuSelection = "Help"
        console.log("help meee")
        setMenu()
      }
    }
  })
  onInput(downKeyTwo, () => {
    if (inMenu)
    {
      if (menuSelection === "Play on PC") {
        PCKeys(); 
        setTimeout(advanceLevel, 0); 
        inMenu = false; 
        inGame = true
      }
      else if (menuSelection === "Play on Console") {
        rebindKeysForConsole(); 
        ConsoleKeys(); 
        setTimeout(advanceLevel, 0); 
        inMenu = false; 
        inGame = true
      }
      else if (menuSelection === "Help") {
        console.log("in help")
        clearText(); 
        setMap(levels[6]); 
        inHelpMenu = true; 
        inMenu= false;
        helpMenuKeys()
      }
    }
  })
}

// function for help menu navigation
function helpMenuKeys() {
  if (inHelpMenu) {
    addHelpMenuText()
    onInput(downKeyTwo, () => {
      inHelpMenu = false;
      inMenu = true;
      clearText();
      setMenu();
      setMap(levels[0])
    })
  }
}

// adds text to help menu
function addHelpMenuText() {
  addText("Back", {
    x:1,
    y:1,
    color: color`9`
  })
  addText("If you need help,", {
    x:1,
    y:3,
    color: color`0`
  })
  addText("please visit this", {
    x:1,
    y:5,
    color: color`0`
  })
  addText("github README: ", {
    x:1,
    y:7,
    color: color`0`
  })
  addText("https://github.com/", {
    x:1,
    y:10,
    color: color`0`
  })
  addText("sridhars650/", {
    x:1,
    y:12,
    color: color`0`
  })
  addText("Sprig-Game", {
    x:1,
    y:14,
    color: color`0`
  })
}

// initial for menu

setMenu() // DEV TESTING UNCOMMENT WHEN DONE

// function for movement input for pc players
function PCKeys()
{
  onInput(upKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).y -= 1;
  });
  
  onInput(leftKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).x -= 1;
  });
  
  onInput(downKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).y += 1;
  });
  
  onInput(rightKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).x += 1;
  });
  
  onInput(upKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).y -= 1;
  });
  
  onInput(leftKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).x -= 1;
  });
  
  onInput(downKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).y += 1;
  });
  
  onInput(rightKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).x += 1;
  });
}

// function for input for console players
function ConsoleKeys()
{
  onInput(upKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).y -= 1;
  });
  
  onInput(leftKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).x -= 1;
  });
  
  onInput(downKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).y += 1;
  });
  
  onInput(rightKeyOne, () => {
    if (!transitioning && inGame) getFirst(player1).x += 1;
  });
  
  onInput(upKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).y -= 1;
  });
  
  onInput(leftKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).x -= 1;
  });
  
  onInput(downKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).y += 1;
  });
  
  onInput(rightKeyTwo, () => {
    if (!transitioning && inGame) getFirst(player2).x += 1;
  });
}


// rebinds the wasd keys for console to make 2 player easier
function rebindKeysForConsole() {
  // player one controls on console
  upKeyOne = "d"
  leftKeyOne = "w"
  rightKeyOne = "s"
  downKeyOne = "a"
  // for player two controls on console
  upKeyTwo = "j"
  leftKeyTwo = "k"
  rightKeyTwo = "i"
  downKeyTwo = "l"
}


afterInput(() => {
  // soccer game functionality
  if (level == 1) {
    // checks for if goal tiles and the ball tile is in one tile
    const ballInLeftGoal = tilesWith(leftGoal, soccerBall).length;
    const ballInRightGoal = tilesWith(rightGoal, soccerBall).length;
    // if player two scored then and its not the end
    if (ballInLeftGoal == 1 && !theEnd && !transitioning) {
      addText("player two wins!", { y: 4, color: color`3` });
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (ballInRightGoal == 1 && !theEnd && !transitioning) {
      addText("player one wins!", { y: 4, color: color`5` });
      player1Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
  }
  // sumo game functionality
  if (level == 2) {
    const playerOneOut = tilesWith(sumoBounds, player1).length;
    const playerTwoOut = tilesWith(sumoBounds, player2).length;
    if (playerOneOut == 1 && !theEnd && !transitioning) {
      addText("player two wins!", { y: 4, color: color`3` });
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (playerTwoOut == 1 && !theEnd && !transitioning) {
      addText("player one wins!", { y: 4, color: color`5` });
      player1Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
  }
  // basketball game functionality
  if (level == 3) { 
    const ballInLeftBasket = tilesWith(bBallBasketLeft, bBall).length;
    const ballInRightBasket = tilesWith(bBallBasketRight, bBall).length;
    // checks if ball is on top of basket
    if (((getFirst(bBall).x == 12) && getFirst(bBall).y == 2))
    {
      isAtTop = true;
      setSolids([player1, player2, soccerBall, bBall, obstacle, obstacle2])
      count = 0
    }
    else if (((getFirst(bBall).x == 2) && getFirst(bBall).y == 2))
    {
      isAtTop = true;
      setSolids([player1, player2, soccerBall, bBall, obstacle, obstacle2])
      count = 0
    }
      // else it counts; this counter is to prevent it from not working when in goal
    else {count++}
    // checks how long it can be set to "on top of basket goal" 
    if (count == 2)
    {
        isAtTop = false;
        setSolids([player1, player2, soccerBall, bBall, obstacle, obstacle2, bBallBasketLeft, bBallBasketRight])
        count = 0;
    }
    // goal functionality
    if (ballInLeftBasket == 1 && !theEnd && !transitioning && isAtTop) {
      addText("player two wins!", { y: 4, color: color`3` });
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (ballInRightBasket == 1 && !theEnd && !transitioning && isAtTop) {
      addText("player one wins!", { y: 4, color: color`5` });
      player1Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
  }
  // the race game functionality
  if (level == 4) {
    const playerOneInFinishLine = tilesWith(finishLine, player1).length;
    const playerTwoInFinishLine = tilesWith(finishLine, player2).length;
    if (playerOneInFinishLine == 1 && !theEnd && !transitioning) {
      addText("player one wins!", { y: 13, color: color`5` });
      player1Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (playerTwoInFinishLine == 1 && !theEnd && !transitioning) {
      addText("player two wins!", { y: 13, color: color`3` });
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
  }
  // hot lava game
  if (level == 5) {
    // hot lava random logic
    if (!theEnd && !transitioning)
    {
      let x = Math.floor((Math.random() * 16));
      let y = Math.floor((Math.random() * 9));
      addSprite(x,y,lava)
    }
    const playerOneInHotZone = tilesWith(lava, player1).length;
    const playerTwoInHotZone = tilesWith(lava, player2).length;
    const playerOneTwoInHotZone = tilesWith(lava, player1,player2).length;
    if (playerOneTwoInHotZone == 1 && !theEnd && !transitioning) {
      addText("tie!", { y: 14, color: color`4` });
      player1Score++;
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (playerOneInHotZone == 1 && !theEnd && !transitioning) {
      addText("player two wins!", { y: 14, color: color`3` });
      player2Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    else if (playerTwoInHotZone == 1 && !theEnd && !transitioning) {
      addText("player one wins!", { y: 14, color: color`5` });
      player1Score++;
      transitioning = true;
      setTimeout(advanceLevel, 3000);
    }
    
  }
})


// this function makes the game advance to the next level
function advanceLevel() {
  // randomization part of code
  if (allLevelsUsed && level !== 6) {
    level = 6;
  } else if (allLevelsUsed) {
    return;
  } else {
    usedLevels.push(level);

    level = Math.floor(Math.random() * 5) + 1; // 1 - 5 num random generator
    while (usedLevels.includes(level)) { // checks if it hasnt been used before
      level = Math.floor(Math.random() * 5) + 1; // if it has, redoes it until it doesnt
    }
    if (usedLevels.length === 5) { // checks if all five games are played
      allLevelsUsed = true; 
    }
  }

  const nextLevel = levels[level];
  if (level === 6) {
    clearText();
    theEnd = true;
    addText("the end!", { y: 1, color: color`H` });
    // descriptions to show player
    if (player1Score > player2Score) {
      addText("winner: blue banana!", { y: 14, color: color`5` });
      addText("final score: " + player1Score + "-" + player2Score, { y: 15, color: color`4` });
    } else if (player2Score > player1Score) {
      addText("winner: red banana!", { y: 14, color: color`3` });
      addText("final score: " + player1Score + "-" + player2Score, { y: 15, color: color`4` });
    } else {
      addText("it's a draw! " + player1Score + "-" + player2Score, { y: 14, color: color`4` });
      addText("final score: " + player1Score + "-" + player2Score, { y: 15, color: color`4` });
    }
  } else if (nextLevel !== undefined) {
    clearText();
    setMap(nextLevel);
    resetGameTitle();
  }

  transitioning = false;
}


